import { getPatientHistory } from '@/api/medical-dashboard'

const medical = {
  state: {
    currentPatient: null,
    visitHistory: []
  },
  mutations: {
    setCurrentPatient(state, patient) {
      state.currentPatient = patient;
    },
    setVisitHistory(state, history) {
      state.visitHistory = history;
    }
  },
  actions: {
    async getVisitHistory({ commit, rootState }, patientId) {
      try {
        const userInfo = rootState.user.userInfo;
        const userId = userInfo ? userInfo.id : null;
        if (!userId) {
          console.error('未获取到用户ID');
          return [];
        }
        const response = await getPatientHistory(userId, patientId);
        const visitHistory = response.result || response.data || [];
        commit('setVisitHistory', visitHistory);
        return visitHistory;
      } catch (error) {
        console.error('获取就诊记录失败:', error);
        return [];
      }
    }
  }
};

export default medical; 